#!/usr/bin/env bash
#
# By mhess https://notabug.org/mhf/Dotfiles

artist=$(cmus-remote -Q | grep -oP "(?<=tag artist ).*$" | tr 'A-Z' 'a-z' |\
 sed -r "s/'//; y/ÃãÀàÂâÄäÁáÈèÊêËëÉéÌìÎîÏïÍíÕõÒòÔôÖöÓóÙùÛûÜüÚúÇçÑñłśåø/aaaaaaaaaaeeeeeeeeiiiiiiiioooooooooouuuuuuuuccnnlsao/; s/\(.*\)//g")
song=$(cmus-remote -Q | grep -oP "(?<=tag title ).*$" | tr 'A-Z' 'a-z' |\
 sed -r "s/'//; y/ÃãÀàÂâÄäÁáÈèÊêËëÉéÌìÎîÏïÍíÕõÒòÔôÖöÓóÙùÛûÜüÚúÇçÑñłśåø/aaaaaaaaaaeeeeeeeeiiiiiiiioooooooooouuuuuuuuccnnlsao/; s/\(.*\)//g")
url="https://www.letras.mus.br/${artist}/${song}"
lyr=$(lynx -dump "$url" | sed -r 'N; /\[14\]/ s/\n//;N; /\[14\]/ s/\n/ - /;N; /\[14\]/ s/\n//')
lyr="${lyr/'[15]'*}"
lyr="${lyr/*'   exibições'}"
echo "$lyr" | sed -r '/^ [0-9]+?.[0-9]?+?$/d; s/\[[0-9]+?\]//' | sed -r '2s/^([^-]+)-\s*([^-]+)/\2 - \1/' | less
